#include<iostream>
#include<cstdio>
using namespace std;
struct node
{
	int bh;
	node *next;
};
node *p, *r, *head;
int main()
{
	int n, m;
	cin >> n >> m;
	while (m != 0 || n != 0)
	{
		//头结点
		head = new node;
		r = head;
		r->bh = 1;
		r->next = NULL;
		//构建链表
		for (int i = 2; i <= n; i++)
		{
			p = new node;
			p->bh = i;
			p->next = NULL;
			r->next = p;
			r = p;
		}
		r->next = head;
		//Link Started!
		int js=0;
		for (int i = 1; i <= n-1; i++)
		{
			for (int j = 1; js <= m - 2; j++)
			{
				r = r->next;
				js++;
			}
			p=r->next;
			r->next=p->next;
			free(p);
			js=0;
		}
		cout << r->bh << endl;
		cin >> n >> m;
	}

	return 0;
}